Home:ALL Converter>Selecting multiple columns from a data frame using dictionary

Selecting multiple columns from a data frame using dictionary

Ask Time:2020-02-24T01:27:32         Author:Aneesha

Json Formatter

I have a data frame with column names

** RI Na Mg Al Si K Ca Ba Fe Type **

Type column is categorical and consists of 4 types. How to extract only RI, Al, Si, Ba columns whose type is 2 using dictionary?

I have tried using the below code:

pd.DataFrame.from_dict(data=df[df['Type']==2], orient='index',columns=['RI','Al','Si','Ba']) 

I am getting an error:

'numpy.ndarray' object is not callable

How do I select only specific columns of type 2?

Author:Aneesha,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364888/selecting-multiple-columns-from-a-data-frame-using-dictionary
yy